<?php

class EstadisticaController extends Controller
{
	public function actionDepartamento()
	{
		if(isset($_POST['fechaInicio'])&&isset($_POST['fechaFin']))
            {
                $arrInicio = explode('/', $_POST['fechaInicio']); 
		$fechaInicio = $arrInicio[2].'-'.$arrInicio[1].'-'.$arrInicio[0]; 
			
		$arrFin = explode('/', $_POST['fechaFin']); 
		$fechaFin = $arrFin[2].'-'.$arrFin[1].'-'.$arrFin[0];
                
                $connection = Yii::app()->db;
                
                $sqlScript = "call reporte_estadistica_departamento('".$fechaInicio." 00:00:00','".$fechaFin." 23:59:59');";
                
                 $command = $connection->createCommand($sqlScript);
			
                $dataReader = $command->query();		
			
		$rows=$dataReader->readAll();				
			
		$connection->active=false;
			
                $dataProvider=new CSqlDataProvider($sqlScript, array(
			    'totalItemCount'=>count($rows),
                            'keyField'=>'Departamento',
			    'pagination'=>array(
			       'pageSize'=>30,
			    ),
			));
                
                $dataProviderR = $dataProvider->getData();
                
			$this->render('departamentoEstadistica',array('dataProvider'=>$dataProvider,'fechaInicio'=>$fechaInicio,'fechaFin'=>$fechaFin));
                   
		
            }else
                $this->render('departamento');
	}

	public function actionIndex()
	{
		$this->render('index');
	}

	public function actionUsuario()
	{
            if(isset($_POST['fechaInicio'])&&isset($_POST['fechaFin']))
            {
                $arrInicio = explode('/', $_POST['fechaInicio']); 
		$fechaInicio = $arrInicio[2].'-'.$arrInicio[1].'-'.$arrInicio[0]; 
			
		$arrFin = explode('/', $_POST['fechaFin']); 
		$fechaFin = $arrFin[2].'-'.$arrFin[1].'-'.$arrFin[0];
                
                $connection = Yii::app()->db;
                
                $sqlScript = "call reporte_estadistica_usuario('".$fechaInicio." 00:00:00','".$fechaFin." 23:59:59');";
                
                 $command = $connection->createCommand($sqlScript);
			
                $dataReader = $command->query();		
			
		$rows=$dataReader->readAll();				
			
		$connection->active=false;
			
                $dataProvider=new CSqlDataProvider($sqlScript, array(
			    'totalItemCount'=>count($rows),
                            'keyField'=>'username',
			    'pagination'=>array(
			       'pageSize'=>30,
			    ),
			));
                
                $dataProviderR = $dataProvider->getData();
                
			$this->render('usuarioEstadistica',array('dataProvider'=>$dataProvider,'fechaInicio'=>$fechaInicio,'fechaFin'=>$fechaFin));
                   
		
            }else
                $this->render('usuario');
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}